package puntaelena.facilitylocation.hillclimbing.solver.agents;

import jfuzzyprincepless.algorithm.structure.IContext2forAgents;
import jfuzzyprincepless.agents.INegotiatingAgent;
import jfuzzyprincepless.negotiation.INegotiationContext;

import java.util.List;
import java.util.ArrayList;

import puntaelena.graphsupport.FacilitiesGraph;
import puntaelena.facilitylocation.hillclimbing.solver.services.IFcltLocDataService;
import puntaelena.facilitylocation.hillclimbing.solver.services.IHillClimbingAgentRegistry;

public class IntroduceClosedFacilitiesMakeCoalitionsContext2forAgents
	implements IContext2forAgents
{
	@Override
	public List<INegotiatingAgent> getAgents(
		INegotiationContext context
	) {
		IFcltLocDataService flServ =
			context.getService(IFcltLocDataService.class);
		IHillClimbingAgentRegistry hcagReg =
			context.getService(IHillClimbingAgentRegistry.class);
		List<INegotiatingAgent> result =
			new ArrayList<INegotiatingAgent>();
		FacilitiesGraph fgraph = flServ.getFgraph();
		CoalitionsRegistry coalitionRegistry =
			new CoalitionsRegistry();

		for (int j = 0; j < fgraph.getFacilitiesCount(); j++) {
			CollaboratingFacilityAgent fVSfagent =
				new CollaboratingFacilityAgent(j);
			result.add(fVSfagent);
			hcagReg.addCollFcltAgent(fVSfagent);
		}

		result.add(coalitionRegistry);

		return result;
	}
}
